<%@ page language="java" pageEncoding="UTF-8" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8;"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,Chrome=1"/>
    <meta name="renderer" content="webkit">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <base target="_top"/>
    <title>创新评测报告</title>
    <link href="<%=basePath%>css/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
    <link href="<%=basePath%>css/basic.css" type="text/css" rel="stylesheet"/>
    <link href="<%=basePath%>css/evaluationUse.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="<%=basePath%>js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>css/bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript" src="<%=basePath%>js/echarts-2.2.7/build/dist/echarts.js"></script>


    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


</head>
<body>
<div class="top">
    <div class="container">
        <img alt="140x140" src="<%=basePath%>images/logo.jpg"/>
    </div>
</div>
<div class="row show-grid daohang">
    <div class="container">
        <div class="daohang-name this"><strong>评测首页</strong></div>
        <a href="<%=basePath%>template/getTemplateAll">
            <div class="daohang-name"><strong>模板列表</strong></div>
        </a>

    </div>
</div>
<div class="container">
    <div class="col-md-12 column">
        <div class="upload"><strong>${template}评测模板</strong></div>
    </div>

    <div class="col-md-12 column">
        <form id="form" enctype="multipart/form-data">
            <div class="intput-text"><input class="form-control" id="uploadFile" placeholder="请选择文件"
                                            disabled="disabled"/></div>
            <div class="fileUpload btn btn-primary">
                <span>选择文件</span>
                <input name="file" id="uploadBtn" type="file" class="upload"
                       accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
                <input name="templateId" type="hidden" value="${templateId}">
            </div>
            <a id="a-download" href="<%=basePath%>evaluation/download?templateId=${templateId}" class="btn btn-success">下载模板表格</a>
            <div class="col-md-12">
                <input type="button" value="提交" id="submitBtn" class="btn btn-success">
            </div>
        </form>


    </div>

</div>

</body>
<script>

    document.getElementById("uploadBtn").onchange = function () {
        document.getElementById("uploadFile").value = this.value;
    };


    $("#submitBtn").click(function () {
        var file = document.getElementById("uploadBtn");
        if (!file.files[0]) {
            alert("请选择上传的文件！");
            return false;
        }
        var fileSize = file.files[0].size;
        var uploadBtn = $("#uploadBtn").val();
//        return false;

        if (fileSize > 1024 * 1024 * 10) {
            alert("文件大小不能超过10M！");
            return false;
        }
        var formData = new FormData($("#form")[0]);
        $.ajax({
            url: "<%=basePath %>evaluation/upload",
            type: "POST",
            dataType:"text",
            async:false,
            cache: false,
            contentType: false,
            processData: false,
            data: formData,
            success: function (data) {
             if((data.toString() == "ok")){
                 alert("上传成功");
                 window.location.href = "<%=basePath %>evaluation/displayAnalysisResult?templateId=${templateId}";
             }else {
                 alert("上传失败");
             }

            },
            error: function (error) {
                alert("上传失败,请检查上传的文件");
            }
        })

    })


</script>
</html>
